package com.zpark.updater;

import com.zpark.entity.HistoryData;
import com.zpark.entity.SuccessData;

import java.util.HashSet;
import java.util.Set;

public class PasswordUpdater extends Updater {
    @Override
    public void update(SuccessData successData, HistoryData historyData, UpdaterChain updaterChain) {
        doUpdate(successData.getOrdernessPassword(),historyData);
        updaterChain.doChain(successData, historyData);
    }

    private void doUpdate(String ordernessPassword, HistoryData historyData) {
        Set<String> historypasswords = historyData.getHistorypasswords();
        if(historypasswords==null|| historypasswords.size()==0){
            historypasswords = new HashSet<>();
        }
        historypasswords.add(ordernessPassword);

        historyData.setHistorypasswords(historypasswords);
    }
}
